% Copyright 2009 Neurosciences Research Foundation, Incorporated
N=21
h=10*rand(1,N);

% h=4*[...%4*[    0.1333    0.4000    0.1333    0.5333    1.0000    0.5333         0    0.4667    0.4000    0.4000    0.5333];
% ...% 4*[   0.3333    0.2000    0.1333    0.2667    0.4667    0.4667    0.0667    0.2000    0.3333    0.4000    0.8667 ];
% ... %4*[   0.2000    0.2667    0.6000    0.2000    0.1333         0         0  0.2667    0.2667    0.3333    0.1333];
% ... % 4*[   0.0667    0.1333    0.1333         0         0    0.2667    0.1333  0         0         0    0.0667];
%     %0.0321    0.4475    0.2013    0.9687    0.1278    0.2822    0.2924    0.1789    0.0484    0.2318    0.7734];
%     %0.7965    0.8375    0.8627    0.0655    0.6800    0.4220    0.9668    0.1903    0.9100    0.5607    0.0139;...
%     %0.0341    0.7960    0.2558    0.2295    0.0283    0.6533    0.7794    0.0992    0.1220    0.5733    0.2672;...
%     0.0185    0.9369    0.0597    0.0331    0.8519    0.9216    0.0863    0.9099    0.3537    0.3028    0.9321;...
%     ];

v=zeros(1,N);
tau=10;
a=exp(-1/tau);
w=4*cos(-1.5*pi:1.5*pi/floor(N/2):1.5*pi)
w(w<0)=w(w<0)*(sum(w(w>0))/abs(sum(w(w<0))));
in=h;

for t=1:10
    v = a*v + (1-a)*in;
    
    out = sqrt(max(0, v ));
    
    in = conv2([out out out],w,'same');
    in = in(length(v)+1:2*length(v))
   
    plot(v,'.-');
    hold on
    plot(h,'r--')
    plot(out,'g-.')
    hold off
    axis([1 N -40 80]);
    pause(.05)
    
end